﻿using System.Collections.ObjectModel;
using System.Windows.Data;
using Iot.AlarmDispose.Database.Entities;

namespace Iot.AlarmDispose.WPF;

public class DefaultRealTimeAlertList<TAlertClassify, TAlertsHistory> : ObservableCollection<TAlertsHistory>,
    IRealTimeAlertList<TAlertClassify, TAlertsHistory>
    where TAlertClassify : class, IAlertClassify
    where TAlertsHistory : class, IAlertsHistory<TAlertClassify>
{
    private readonly object _lockObj = new();

    public DefaultRealTimeAlertList()
    {
        BindingOperations.EnableCollectionSynchronization(this, _lockObj);
    }

    public void AddAlarm(TAlertsHistory item)
    {
        lock (_lockObj)
        {
            Insert(0, item);
        }
    }

    public void RemoveAlarm(TAlertsHistory item)
    {
        lock (_lockObj)
        {
            Remove(item);
        }
    }
}